﻿using System;

//Largest palindrome product
// Problem 4

// A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
// Find the largest palindrome made from the product of two 3-digit numbers.
namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var start = DateTime.Now;

            long i;

            i = findPalindromic();

            Console.WriteLine(i);

            var end = DateTime.Now;
            var time = end - start;

            Console.WriteLine("Time: {0}", time);
        }

        public static int findPalindromic()
        {
            int palindromic = -1;

	        for (var a = 999; a >= 100; a--) {
                for (var b = 999; b >= 100; b--) {
                    var c = a * b;

                    var s = c.ToString();
                    var arr = s.ToCharArray();
                    Array.Reverse(arr);

                    if (s == String.Join("", arr)) {
                        if (palindromic < c) {
                            palindromic = c;
                        }
                    }
                }
            }

	        return palindromic;
        }
    }
}
